﻿<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#container {width: 100%;height: 100%;overflow: hidden;margin:0;}
</style>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>

</head>
<body scroll="no" bgcolor="#FFFFFF">
    <div id="container">
    </div>
    <div style="display: inline;">
        <span>
            <input name="emergency" style="width: 68px; height: 25px; font-size: 12px; font-family: 微软雅黑;
                display: none;" type="button" id="greenDetect" class="auto-style1"
                value="绿色监测"/></span>
    </div>
</body>
</html>
<script type="text/javascript">
    var map = new BMap.Map("container");            // 创建Map实例
    var point = new BMap.Point(121.506837, 31.289236);    // 创建点坐标
    map.centerAndZoom(point, 15);                     // 初始化地图,设置中心点坐标和地图级别。
    map.addControl(new BMap.NavigationControl());
    map.addControl(new BMap.ScaleControl());
    map.enableScrollWheelZoom();


    // 复杂的自定义覆盖物
    function ComplexCustomOverlay(point, text, mouseoverText) {
        this._point = point;
        this._text = text;
        this._overText = mouseoverText;
    }
    ComplexCustomOverlay.prototype = new BMap.Overlay();
    ComplexCustomOverlay.prototype.initialize = function (map) {
        this._map = map;
        var div = this._div = document.createElement("div");
        div.style.position = "absolute";
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        div.style.backgroundColor = "#EE5D5B";
        div.style.border = "1px solid #BC3B3A";
        div.style.color = "white";
        div.style.height = "18px";
        div.style.padding = "2px";
        div.style.lineHeight = "18px";
        div.style.whiteSpace = "nowrap";
        div.style.MozUserSelect = "none";
        div.style.fontSize = "12px"
        var span = this._span = document.createElement("span");
        div.appendChild(span);
        span.appendChild(document.createTextNode(this._text));
        var that = this;

        var arrow = this._arrow = document.createElement("div");
        arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
        arrow.style.position = "absolute";
        arrow.style.width = "11px";
        arrow.style.height = "10px";
        arrow.style.top = "22px";
        arrow.style.left = "10px";
        arrow.style.overflow = "hidden";
        div.appendChild(arrow);

        div.onmouseover = function () {
            this.style.backgroundColor = "#6BADCA";
            this.style.borderColor = "#0000ff";
            this.getElementsByTagName("span")[0].innerHTML = that._overText;
            arrow.style.backgroundPosition = "0px -20px";
        }

        div.onmouseout = function () {
            this.style.backgroundColor = "#EE5D5B";
            this.style.borderColor = "#BC3B3A";
            this.getElementsByTagName("span")[0].innerHTML = that._text;
            arrow.style.backgroundPosition = "0px 0px";
        }

        map.getPanes().labelPane.appendChild(div);

        return div;
    }
    ComplexCustomOverlay.prototype.draw = function () {
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
        this._div.style.top = pixel.y - 30 + "px";
    }



</script>
<script type="text/javascript">
    $(document).ready(function () {
        var emergency = document.getElementById('greenDetect').value;
        window.external.ClickEvent(emergency);
        Addpoint();
    });
    function Addpoint() {
        var jsonconf = $.parseJSON(window.external.name);
        var points = [];
        map.clearOverlays();
        for (var i = 0; i < jsonconf.length; i++) {
            addMarker(new BMap.Point(jsonconf[i].Longitude, jsonconf[i].Latitude), jsonconf[i].Name, jsonconf[i].Water, jsonconf[i].Energy);
            points.push(new BMap.Point(jsonconf[i].Longitude, jsonconf[i].Latitude));
        }
        map.setViewport(points);
    }

    function addMarker(point1, text, water, energy) {
        var mouseoverTxt = "水耗：" + water + ", 能耗：" + energy;
        var myCompOverlay = new ComplexCustomOverlay(point1, mouseoverTxt, mouseoverTxt);
        map.addOverlay(myCompOverlay);


        var sContent =
            "<div><h4 style='margin:0 0 5px 0;padding:0.2em 0'>" + name + "</h4>" +
            "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em;width:180px;'>" + name + " " + water + "</p>" + "能耗：" + energy +
            "</div>";

        var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
        myCompOverlay.addEventListener("click", function () {
            this.openInfoWindow(infoWindow);
            //图片加载完毕重绘infowindow
        });
    }

    function addMarker1(point1, text, water, energy) {
        var marker = new BMap.Marker(point1);
        map.addOverlay(marker);
        var label = new BMap.Label(text, { offset: new BMap.Size(20, -10) });
        marker.setLabel(label);

        var sContent =
            "<div><h4 style='margin:0 0 5px 0;padding:0.2em 0'>" + text + "</h4>" +
            "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em;width:180px;'>" + water + "</p>" + "能耗：" + energy +
            "</div>";

        var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
        marker.addEventListener("click", function () {
            this.openInfoWindow(infoWindow);
            //图片加载完毕重绘infowindow
        });
    }
</script>
